import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import store from './store'
import globalConfig from './utils/config'
import ElementUI from 'element-ui'
import echarts from 'echarts'
import dataV from '@jiaminghi/data-view'
import PaginationView from '@/components/PaginationView.vue'
import VideoPlayer from 'vue-video-player/src'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(dataV)
axios.defaults.baseURL = ''
Vue.use(ElementUI)
Vue.use(VideoPlayer)
const throttle = {
  bind: (el, binding) => {
    let throttleTime = binding.value // 防抖时间
    if (!throttleTime) { // 用户若不设置防抖时间，则默认1s
      throttleTime = 1000
    }
    let timer
    let disable = false
    el.addEventListener('click', event => {
      if (timer) {
        clearTimeout(timer)
      }
      if (!disable) { // 第一次执行(一点击触发当前事件)
        disable = true
      } else {
        event && event.stopImmediatePropagation()
      }
      timer = setTimeout(() => {
        timer = null
        disable = false
      }, throttleTime)
    }, true)
  }
}
Vue.directive('throttle', throttle)
const setHtmlFontSize = () => {
  const htmlDom = document.getElementsByTagName('html')[0]
  let htmlWidth =
    document.documentElement.clientWidth || document.body.clientWidth
  if (htmlWidth > 1350) {
    // htmlWidth = 1920
  } else {
    htmlWidth = 1500
  }
  htmlDom.style.fontSize = `${htmlWidth / 19.2}px`
}
window.onresize = setHtmlFontSize
setHtmlFontSize()

Vue.component('PaginationView', PaginationView)
Vue.config.productionTip = false
Vue.prototype.$config = globalConfig
Vue.prototype.$echarts = echarts
new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount('#app')
